/*     */ package com.newcrm.db;
/*     */ 
/*     */ import com.newcrm.exception.DBException;
/*     */ import java.sql.Connection;
/*     */ import java.sql.SQLException;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.dbutils.DbUtils;
/*     */ import org.apache.commons.dbutils.MyMapListHandler;
/*     */ import org.apache.commons.dbutils.QueryRunner;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class NameManager
/*     */ {
/*  19 */   private static Logger logger = Logger.getLogger(NameManager.class.getName());
/*     */ 
/*     */   public List<Map<String, Object>> searchDealName(int companyId, String term, boolean isAdmin, String loginUserId, int groupId)
/*     */     throws DBException, SQLException
/*     */   {
/*  36 */     if ((term == null) || (term.trim().length() == 0)) {
/*  37 */       return null;
/*     */     }
/*  39 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  40 */     if (conn == null) {
/*  41 */       throw new DBException();
/*     */     }
/*     */ 
/*  50 */     StringBuffer sql = new StringBuffer("SELECT A.DealId AS id, A.LastContactDate, 3, ResponsibleUserId AS ShowUserId, A.Name AS label, A.Name AS value FROM T_Deal_Info AS A INNER JOIN T_Customer_Info AS B ON A.CustomerId = B.CustomerId WHERE B.DeleteFlag = 0 AND A.CompanyId = ? AND A.Name like ?");
/*  51 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/*     */       List localList;
/*  53 */       if (isAdmin) {
/*  54 */         sql.append(" ORDER BY A.LastContactDate DESC LIMIT 0, 10");
/*  55 */         return (List)runner.query(conn, sql.toString(), 
/*  56 */           new MyMapListHandler(), new Object[] { Integer.valueOf(companyId), "%" + term + "%" });
/*     */       }
/*     */ 
/*  68 */       if (groupId <= 0)
/*     */       {
/*  70 */         sql.append(
/*  71 */           " AND (B.Visible = ? OR (B.Visible = ? AND B.PermissionsId = ?)) ")
/*  72 */           .append(" ORDER BY A.lastContactDate DESC LIMIT 0, 10");
/*  73 */         return (List)runner.query(conn, sql.toString(), 
/*  74 */           new MyMapListHandler(), new Object[] { Integer.valueOf(companyId), "%" + term + "%", 
/*  75 */           Integer.valueOf(1), Integer.valueOf(4), 
/*  76 */           loginUserId });
/*     */       }
/*     */ 
/*  79 */       sql.append(
/*  80 */         " AND (B.Visible = ? OR (B.Visible = ? AND B.PermissionsId IN (SELECT UserId FROM T_User_Info WHERE CompanyId = ? AND GroupId = ?))) ")
/*  81 */         .append(" ORDER BY A.lastContactDate DESC LIMIT 0, 10");
/*  82 */       return (List)runner.query(conn, sql.toString(), 
/*  83 */         new MyMapListHandler(), new Object[] { Integer.valueOf(companyId), "%" + term + "%", 
/*  84 */         Integer.valueOf(1), Integer.valueOf(4), 
/*  85 */         Integer.valueOf(companyId), Integer.valueOf(groupId) });
/*     */     }
/*     */     finally {
/*     */       try {
/*  89 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  91 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public List<Map<String, Object>> searchCustomerName(int companyId, String term, boolean isAdmin, String loginUserId, int groupId, boolean isAPP)
/*     */     throws DBException, SQLException
/*     */   {
/* 120 */     if ((term == null) || (term.trim().length() == 0)) {
/* 121 */       return null;
/*     */     }
/* 123 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 124 */     if (conn == null) {
/* 125 */       throw new DBException();
/*     */     }
/*     */ 
/* 134 */     StringBuffer sql = null;
/*     */ 
/* 136 */     if (isAPP)
/* 137 */       sql = new StringBuffer("SELECT CustomerId, Type, Name FROM T_Customer_Info WHERE DeleteFlag = 0 AND CompanyId = ? AND Name like ?");
/*     */     else {
/* 139 */       sql = new StringBuffer("SELECT CustomerId AS id, LastContactDate, Type, PermissionsId as ShowUserId, Name as label, Name as value FROM T_Customer_Info WHERE DeleteFlag = 0 AND CompanyId = ? AND Name like ?");
/*     */     }
/* 141 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/*     */       List localList;
/* 143 */       if (isAdmin)
/*     */       {
/* 147 */         sql.append(" ORDER BY LastContactDate DESC LIMIT 0, 10");
/* 148 */         return (List)runner.query(conn, sql.toString(), 
/* 149 */           new MyMapListHandler(), new Object[] { Integer.valueOf(companyId), "%" + term + "%" });
/*     */       }
/*     */ 
/* 161 */       if (groupId <= 0)
/*     */       {
/* 163 */         sql.append(
/* 164 */           " AND (Visible = ? OR (Visible = ? AND PermissionsId = ?)) ")
/* 165 */           .append(" ORDER BY lastContactDate DESC LIMIT 0, 10");
/*     */ 
/* 172 */         return (List)runner.query(conn, sql.toString(), 
/* 173 */           new MyMapListHandler(), new Object[] { Integer.valueOf(companyId), "%" + term + "%", 
/* 174 */           Integer.valueOf(1), Integer.valueOf(4), 
/* 175 */           loginUserId });
/*     */       }
/*     */ 
/* 178 */       sql.append(
/* 179 */         " AND (Visible = ? OR (Visible = ? AND PermissionsId IN (SELECT UserId FROM T_User_Info WHERE CompanyId = ? AND GroupId = ?))) ")
/* 180 */         .append(" ORDER BY lastContactDate DESC LIMIT 0, 10");
/*     */ 
/* 185 */       return (List)runner.query(conn, sql.toString(), 
/* 186 */         new MyMapListHandler(), new Object[] { Integer.valueOf(companyId), "%" + term + "%", 
/* 187 */         Integer.valueOf(1), Integer.valueOf(4), 
/* 188 */         Integer.valueOf(companyId), Integer.valueOf(groupId) });
/*     */     }
/*     */     finally {
/*     */       try {
/* 192 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 194 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.NameManager
 * JD-Core Version:    0.6.1
 */